package com.pd.backend.service.impl;

import com.pd.backend.entity.PdMember;
import com.pd.backend.dao.PdMemberDao;
import com.pd.backend.service.PdMemberService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 用户表(PdMember)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:33
 */
@Service("pdMemberService")
public class PdMemberServiceImpl implements PdMemberService {
    @Resource
    private PdMemberDao pdMemberDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdMember queryById(String id) {
        return this.pdMemberDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdMember    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdMember> queryByPage(PdMember pdMember, PageRequest pageRequest) {
        long total = this.pdMemberDao.count(pdMember);
        return new PageImpl<>(this.pdMemberDao.queryAllByLimit(pdMember, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdMember 实例对象
     * @return 实例对象
     */
    @Override
    public PdMember insert(PdMember pdMember) {
        this.pdMemberDao.insert(pdMember);
        return pdMember;
    }

    /**
     * 修改数据
     *
     * @param pdMember 实例对象
     * @return 实例对象
     */
    @Override
    public PdMember update(PdMember pdMember) {
        this.pdMemberDao.update(pdMember);
        return this.queryById(pdMember.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdMemberDao.deleteById(id) > 0;
    }
}
